// pages/main/release_course/release_course.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    type_array:['通识一般选修课','英语课','心理选修课','体育课'],
    type_index:0,
    week_array:['星期一','星期二','星期三','星期四','星期五','星期六','星期日'],
    week_index:0,
    time_array:['1-2节','3-4节','3-5节','6-7节','6-8节','6-9节','8-9节','10-11节','10-12节'],
    time_index:0,
    allValue:''
  },
  formSubmit:function(e){
    this.setData({
      allValue:e.detail.value
    })
  },
  bindTypeChange:function(e){
    this.setData({
      type_index:e.detail.value
    })
  },
  bindTimeChange:function(e){
    this.setData({
      time_index:e.detail.value
    })
  },
  bindWeekChange:function(e){
    this.setData({
      week_index:e.detail.value
    })
  },

  addClass: function (res) {
    var data = res.detail.value
    const db = wx.cloud.database()
    db.collection('class').add({
      data: {
        person_name: getApp().globalData.user.name,
        class_name: data.release_class_name,
        type: this.data.type_array[data.release_class_type],
        teacher: data.release_class_teacher,
        week: this.data.week_array[data.release_class_time_week],
        time: this.data.time_array[data.release_class_time_time],
        phone: getApp().globalData.user.phone
      },
      success: (res) => {
        wx.showToast({
          title: '发布成功',
          icon: 'success',
          duration: 2500
        })
        wx.navigateBack({
          delta: 1
        })
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  return:function(){
    wx.navigateBack({
      delta:1
    })
  },
})